﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MapObjectClassLibrary
{
    public class Polygon
    {
        private List<PointD> _Points = new List<PointD>();

        public Polygon() { }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="ps">点数组</param>
        public Polygon(PointD[] ps)
        {
            _Points.AddRange(ps);
        }

        /// <summary>
        /// 获取和设置所有点
        /// </summary>
        public PointD[] Points
        {
            get { return _Points.ToArray(); }
            set
            {
                _Points.Clear();
                _Points.AddRange(value);
            }
        }

        /// <summary>
        /// 顶点数
        /// </summary>
        public int PointsCount
        {
            get { return _Points.Count; }
        }

        /// <summary>
        /// 获取指定索引的点
        /// </summary>
        /// <param name="index">索引，从0开始</param>
        /// <returns></returns>
        public PointD GetPoint(int index)
        {
            return _Points[index];
        }

        public void AddPoint(PointD p)
        {
            _Points.Add(p);
        }

        public void Clear()
        {
            _Points.Clear();
        }

        public Polygon Clone()
        {
            Polygon polygon = new Polygon();
            foreach (PointD p in _Points)
            {
                polygon.AddPoint(p.Clone());
            }
            return polygon;
        }
    }
}
